//
//  LWTopCell.m
//  LWShopItem
//
//  Created by mac on 17/3/26.
//  Copyright © 2017年 LWShop.com. All rights reserved.
//

#import "LWTopCell.h"
#import <Masonry.h>
#import "UIColor+Addition.h"
#import "LWWebViewController.h"
#import "LWNutWebViewController.h"
#import "LWEntranceWebViewController.h"
#import "LWRelaxationWebVc.h"
#import "LWPlaceWebVc.h"

@implementation LWTopCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

#pragma MARK - UI
- (void)setupUI
{
    self.backgroundColor = [UIColor colorWithHex:0xF2F2F2];
    
    //临网广告位图片
    UIButton *imageBtn = [[UIButton alloc]init];
    
    [imageBtn addTarget:self action:@selector(justAd:) forControlEvents:UIControlEventTouchUpInside];
    
    [imageBtn setImage:[UIImage imageNamed:@"h1"] forState:UIControlStateNormal];
    
    [self.contentView addSubview:imageBtn];
    
    [imageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        
        make.top.equalTo(self).offset(20);
        
        make.left.equalTo(self).offset(10);
        
        make.width.equalTo(self.mas_width).multipliedBy(0.5);//设置宽度为self.view的一半，multipliedBy是倍数的意思，也就是，使宽度等于self.view宽度的0.5倍
        make.height.equalTo(self.mas_height).multipliedBy(0.58);//设置高度为self.view高度的一半

    }];
    
    //去除点击效果
    imageBtn.adjustsImageWhenHighlighted = NO;
    
    
    UIButton *imageBtn2 = [[UIButton alloc]init];
    
    [imageBtn2 addTarget:self action:@selector(nutClick) forControlEvents:UIControlEventTouchUpInside];
    
    [imageBtn2 setImage:[UIImage imageNamed:@"h2"] forState:UIControlStateNormal];
    
    [self.contentView addSubview:imageBtn2];
    
    [imageBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self).offset(20);
        
        make.left.equalTo(imageBtn.mas_right).offset(6);
        
        make.right.equalTo(self).offset(-10);
        
        make.width.equalTo(self.mas_width).multipliedBy(0.43);//设置宽度为self.view的一半，multipliedBy是倍数
        
        make.height.equalTo(imageBtn.mas_height).multipliedBy(0.48);//设置高度为self.view高度的一半
        
    }];
    
    UIButton *imageBtn3 = [[UIButton alloc]init];
    
    [imageBtn3 addTarget:self action:@selector(enterClick) forControlEvents:UIControlEventTouchUpInside];
    
    [imageBtn3 setImage:[UIImage imageNamed:@"h3"] forState:UIControlStateNormal];
    
    [self.contentView addSubview:imageBtn3];
    
    [imageBtn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(imageBtn.mas_bottom);
        
        make.left.equalTo(imageBtn.mas_right).offset(10);
        
        make.width.equalTo(imageBtn2);
        
        make.height.equalTo(imageBtn2);
        
    }];
    
    UIButton *imageBtn4 = [[UIButton alloc]init];
    
    [imageBtn4 addTarget:self action:@selector(fallowClick) forControlEvents:UIControlEventTouchUpInside];
    
    [imageBtn4 setImage:[UIImage imageNamed:@"h4"] forState:UIControlStateNormal];
    
    [self.contentView addSubview:imageBtn4];
    
    [imageBtn4 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self).offset(10);
        
        make.top.equalTo(imageBtn.mas_bottom).offset(10);
        
        make.width.equalTo(self.mas_width).multipliedBy(0.5);//设置宽度为self.view的一半，multipliedBy是倍数
        
        make.height.equalTo(imageBtn.mas_height).multipliedBy(0.5);
        
        
        
    }];
    
    UIButton *imageBtn5 = [[UIButton alloc]init];
    
    [imageBtn5 addTarget:self action:@selector(spaceClick) forControlEvents:UIControlEventTouchUpInside];
    
    [imageBtn5 setImage:[UIImage imageNamed:@"h5"] forState:UIControlStateNormal];
    
    [self.contentView addSubview:imageBtn5];
    
    [imageBtn5 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(imageBtn.mas_bottom).offset(10);
        
        make.left.equalTo(imageBtn4.mas_right).offset(10);
        
        make.width.equalTo(imageBtn2);
        
        make.height.equalTo(imageBtn2);
        
    }];
    
}

#pragma MARK - 处理点击事件
-(void)justAd:(UIButton *)btn
{
    NSLog(@"点击了进入临网商城按钮");
    
    LWWebViewController *webVc = [LWWebViewController new];
    
    [self.viewController presentViewController:webVc animated:YES completion:nil];
    
       
}

- (void)nutClick
{
    NSLog(@"点击了坚果炒货广告页");
    LWNutWebViewController *webVc = [LWNutWebViewController new];
    
    [self.viewController presentViewController:webVc animated:YES completion:nil];
    
}

- (void)enterClick
{
    NSLog(@"点击了进口食品广告页");
    LWEntranceWebViewController *webVc = [LWEntranceWebViewController new];
    
    [self.viewController presentViewController:webVc animated:YES completion:nil];
}

- (void)fallowClick
{
    NSLog(@"点击了休闲食品广告页");
    LWRelaxationWebVc *webVc = [LWRelaxationWebVc new];
    
    [self.viewController presentViewController:webVc animated:YES completion:nil];
}

- (void)spaceClick
{
    NSLog(@"点击了地方特产广告页");
    LWPlaceWebVc *webVc = [LWPlaceWebVc new];
    
    [self.viewController presentViewController:webVc animated:YES completion:nil];
    
}

@end
